package com.FH.organization.emailRevice;

import com.FH.organization.emailSend.emailsendPullDTO;
import com.FH.util.ResultDTO;

import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

/**
 * Created by Administrator on 2016/9/5.
 */


@Path("/email")
@Produces(MediaType.APPLICATION_JSON)
@RequestScoped
public class emialResource {
    @EJB
    private emailDAO email;

    @GET
    @Path("/{search}&{page}&{size}")
    public ResultDTO getEmailInfo(@PathParam("search") String search, @PathParam("page") String page, @PathParam("size") String size) {
        //添加分页查询
        if (null == page || "".equals(page) || "0".equals(page)) {
            page = "1";    //默认从第1页开始查起
        }/*else
        {
            page =((Integer.parseInt(page)-1)*Integer.parseInt(size))+"";
        }*/
        if (null == size || "".equals(size)) {
            size = "10";//默认10行数据
        }
        return email.getemailInfo(search, page, size);
    }

    @GET
    @Path("/emailsendinfo/{search}&{page}&{size}")
    public ResultDTO getEmailsendInfo(@PathParam("search") String search, @PathParam("page") String page, @PathParam("size") String size) {
        //添加分页查询
        if (null == page || "".equals(page) || "0".equals(page)) {
            page = "1";    //默认从第1页开始查起
        }/*else
        {
            page =((Integer.parseInt(page)-1)*Integer.parseInt(size))+"";
        }*/
        if (null == size || "".equals(size)) {
            size = "10";//默认10行数据
        }
        return email.getemail_sedInfo(search, page, size);
    }


    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO addEmailInfo(emailPullDTO emailDTO) {
        return email.addemailInfo(emailDTO);
    }

    @PUT
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO deleteEmailInfo(emailPullDTO emailDTO) {
        return email.deleteEmailInfo(emailDTO);
    }

    @PUT
    @Path("/deletesend")
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO deleteEmailsendInfo(emailsendPullDTO emailDTO) {
        return email.deleteEmailsendInfo(emailDTO);
    }

    @PUT
    @Path("/update")
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO updateEmailInfo(emailPullDTO emailDTO) {
        return email.updateEmailInfo(emailDTO);
    }

//    @PUT
//    @Path("/deletereceiver")
//    @Consumes(MediaType.APPLICATION_JSON)
//    public ResultDTO deleteEmailreceiverInfo(emailPullDTO emailDTO) {
//        return email.deleteEmailreceiverInfo(emailDTO);
//    }

    @POST
    @Path("/send")
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO sendEmail(emailsendPullDTO emailsend) {
        return email.sendEmail(emailsend);
    }

    @GET
    @Path("/two/{search}")
    public ResultDTO receiverEmail(@PathParam("search") String search) {
        return email.receiverEmail(search);
    }

}
